Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
How to prevent screen holding on "touchstart"?

I’m trying to create a small game as a learning experience and I’m having trouble adding a jump function. The game is for mobile touch screens.

Essentially I have a gravity variable which is applied to the player on the canvas (which works fine) and an accelerate function for up/down movement.

I need to be able to tap the screen and have the "player" jump, then fall back down. so far I have:

document.addEventListener
(“touchstart”,jump) 
function jump() {
 accelerate(-0.5);
}

document.addEventListner
("touchend”,fall)
function fall() {
 accelerate(0.4)
}

I might not have remembered what I wrote exactly, but the above code works for rising and falling, the problem however is if the user holds the screen, the player will just keep rising. Now obviously logically this is to be expected but I want more of a tap screen to jump type thing

so is there a way to have the accelerate run once when the user taps the screen, perhaps for a set duration then stops, until the screen is tapped again?

sorry for the long post

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda